/*
 * Copyright 2008 Nils Adermann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ARRAY_H
#define ARRAY_H

#include "Value.h"
#include <vector>

namespace Couch
{
	namespace JSON
	{
		/**
		* Represents a JSON Array containing a list of values.
		*
		* This class implements a JSON Array using a STL vector. Its interface
		* is similar to that of a standard vector. Alternatively you can still
		* retrieve the vector itself and work with that directly using
		* getVector().
		*
		* The array stores pointers to the values. On destruction all values
		* stored by the array are deleted. Following this behaviour erase()
		* deletes the value as well. So make sure you copy data if you wish to
		* continue using it after destructing the array.
		*/
		class Array : public Value
		{
		public:
			Array();
			Array(const Array& a);
			~Array();

			size_t size() const;
			bool empty() const;
			Value*& at(size_t pos);
			const Value* at(size_t pos) const;
			Value*& operator[](const size_t pos);
			const Value* operator[](const size_t pos) const;
			Array& operator=(const Array& a);
			Value*& front();
			Value*& back();
			const Value* front() const;
			const Value* back() const;
			std::vector<Value*>::iterator begin();
			std::vector<Value*>::iterator end();
			std::vector<Value*>::const_iterator begin() const;
			std::vector<Value*>::const_iterator end() const;
			void push_back(Value* value);
			void pop_back();
			void insert(size_t index, Value* value);
			void insert(std::vector<Value*>::iterator it, Value* value);
			void erase(size_t index);
			void erase(std::vector<Value*>::iterator it);
			std::vector<Value*>* getVector();
			const std::vector<Value*>* getVector() const;
			Array& toArray();
			const Array& toArray() const;
			void toJSON(UnicodeString* u) const;
		private:
			std::vector<Value*>* vector;
		};
	}
}

#endif
